package itea.bignews.dwr;

import org.directwebremoting.WebContextFactory;

import com.javaeedev.openid.Association;
import com.javaeedev.openid.Authentication;
import com.javaeedev.openid.Endpoint;
import com.javaeedev.openid.OpenIdManager;

/**
 * Authentication & Authorization
 * @version $Id: AuthDwr.java 50 2009-09-07 13:39:17Z iteahere $
 * @author itea
 * @date 2009-8-14
 */
public class AuthDwr extends Dwr{

	private String returnTo;
	private String realm;
	
	public String signInWithGoogle() {
		OpenIdManager manager = new OpenIdManager();
		manager.setReturnTo(returnTo);
		manager.setRealm(realm);

		Endpoint endpoint = manager.lookupEndpoint("Google");
		Association association = manager.lookupAssociation(endpoint);
		String url = manager.getAuthenticationUrl(endpoint, association);
		
		WebContextFactory.get().getSession().setAttribute("association", association);
		WebContextFactory.get().getSession().setAttribute("openIdManager", manager);
		
		return url;
	}

	public void setReturnTo(String returnTo) {
		this.returnTo = returnTo;
	}

	public void setRealm(String realm) {
		this.realm = realm;
	}
}
